<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/FCKeditor.tld" prefix="fck" %>
<%@page import="java.util.*,model.*,util.*,control.*,java.text.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<body>
<div>
  <%
				request.setCharacterEncoding("utf-8"); 
				String username=request.getParameter("username");
				String pwd=request.getParameter("userPassword");
				String logType=request.getParameter("logType");
				String verification=request.getParameter("verification");
				String code=(String)session.getAttribute("code");
				
			   	session.setAttribute("flag",null);
				session.setAttribute("userId",null);
				if( username == "" || username == null || pwd == "" || pwd == null )
				{		
				%>
				<script language="javascript">
				     alert("用户名或密码不能为空请重新登录");
				     window.location.href="index.jsp";
			    </script>
  <%
					return ;
				}			
			
				/*out.print(username);
				out.print(logType);
				*/
				
				if( logType.equals("Admin")  )
				{			
					Admin admin = new Admin();
					AdminControl ac = new AdminControl();
					//2011-12-01 根据用户名获取记录
					//2011-12-01 userId
					admin = ac.GetAdmin(username);
					
					if(admin!=null) 
					{
						int userId_int = admin.getAdminId();
						String userId = String.valueOf(userId_int);
						if( pwd.equals(admin.getPassword()))
						{
							if(!verification.equals(code)) {
								%>
  <script language="javascript">
							     alert("验证码错误");
							     window.location.href="index.jsp?username=<%=username%>";
							     </script>
  <%
    							 return ;
							}//if 验证码
							
							session.setAttribute("flag","admin");
							session.setAttribute("userId",userId);
							//<%admin.getName()
  %>
  <script language="javascript">
						     alert("支持多终端自适应测试系统欢迎您！");
						     window.location.href="pages/admin/index.jsp";
						    </script>
  <%
							return ;
						}
					}
				}
				else if(logType.equals("Student")  )
				{
					Student student = new Student();
					StudentControl sc = new StudentControl();
					//2011-12-01 根据用户名获取记录
					student = sc.GetStudent(username);
										
					if(student!=null)
					{
						int userId_int = student.getStudentId();
						String userId = String.valueOf(userId_int);
						if( pwd.equals( student.getPassword()) )
						{		
							if(!verification.equals(code)) {
								%>
 							 <script language="javascript">
							     alert("验证码错误");
							     window.location.href="index.jsp?username=<%=username%>";
						     </script>
  <%
    							 return ;
							}
							session.setAttribute("flag","student");
							session.setAttribute("userId",userId);
						%>
  <script language="javascript">
							     alert("支持多终端自适应测试系统欢迎您！");
							     window.location.href="pages/student/student_index.jsp";
							    </script>
  <%
							return ;
						}
					}
				}
				%>
  <script language="javascript">
					     alert("用户名或密码错误,请重新登录！");
					     window.location.href="index.jsp";
					    </script>
  <%
			
			 %>
</div>
</body>
</html>
